
function loadFriends() 
{	
	var params = {};
	params[opensocial.DataRequest.PeopleRequestFields.MAX] = 5000;	
	  var req = opensocial.newDataRequest();	
		req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS,params), 'viewer_friends');
	  req.send(onLoadFriends);
}

function onLoadFriends(data) {  
  var friends = new Array();  
  var viewerFriends = data.get('viewer_friends').getData();
  html = new Array();
  html.push('<select id="person">');
  viewerFriends.each(function(person) {
    html.push('<option value="' + person.getId() + '">' + person.getDisplayName() + "</option>");
    
    friends[person.getId()] = person.getDisplayName();
  });
  html.push('</select>');
  document.getElementById('friends').innerHTML = html.join('');  
}

function requestSendMessage(){
	
	var recipient = document.getElementById('person').value;
	 
	var params = {};
	params[opensocial.Message.Field.TITLE]="Hello";
	var body="Please Check This Application.";   
	var message = opensocial.newMessage(body, params);
	
	opensocial.requestSendMessage(recipient, message);
}

 function create_unique_random_array(num_elements,min,max) 
 {
		var temp, nums = new Array;
		for (var element=0; element < num_elements; element++) 
		{
			while ((temp = number_found ( random_number ( min, max ), nums )) == -1 )
			{
			}
			nums[element] = temp;
		}
		return (nums);
}
function number_found (random_number,number_array) 
{
		for (var element=0; element < number_array.length; element++) 
		{
			if (random_number == number_array[element]) 
			{
				return ( -1 );
			}
		}
		return ( random_number );
}
function random_number(min,max) 
{
    return (Math.round((max-min) * Math.random() + min));
}


 function postActivity(text) {  
    var params = {};  
    params[opensocial.Activity.Field.TITLE] = text;
    var activity = opensocial.newActivity(params); 
    opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH,callback);
  };   
  
  function callback(status) {
    if (status.hadError())
    {
     // alert("Error creating activity.");
    }
    else 
    {
     // alert("Activity successfully created.");
    }
  };

   
  function populateMyAppData() {
	
	var prefs = new gadgets.Prefs();
	
	var div = document.getElementById('content_div');
	div.innerHTML = "";
	var htmlout = "";
	var table1html = "";
	var table2html = "";
htmlout += "<table style='background-color:#FFF;font-family:Verdana, Arial, Helvetica, sans-serif;' cellpadding='0' cellspacing='0' width='100%'>";
   htmlout +="<tr><td colspan='2'><b>Quiz Questions</b></td></tr>";
   htmlout +="<tr><td colspan='2' style='height:10px;'></td></tr>";
   
    table1html += "<table style='background-color:#FFF;font-family:Verdana, Arial, Helvetica, sans-serif;' cellpadding='0' cellspacing='0' width='100%'>"
	 table2html += "<table style='background-color:#FFF;margin-left:25px;font-family:Verdana, Arial, Helvetica, sans-serif;' cellpadding='0' cellspacing='0' width='100%'>"
   
   var me = null;
   
   var myNumArray = create_unique_random_array( 10, 1, 20 );
   var data1 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Who do you consider an ideal leader?</b></td></tr></table>";
	data1 += "<input type='radio' name='data1' value='4' />Mahatma Gandhi<br />";
    data1 += "<input type='radio' name='data1' value='3' />Shane Warne<br />";
    data1 += "<input type='radio' name='data1' value='2' />Barrack Obama<br /><br />";
	 data1 += "<input type='radio' name='data1' value='1' />Adolf Hitler<br /><br />";
   // htmlout += data1+ "<br />";
	
	var data2 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Which business leader inspires you?</b></td></tr></table>";
	data2 += "<input type='radio' name='data2' value='4' />Ratan Tata<br />";
    data2 += "<input type='radio' name='data2' value='3' />Anil Ambani<br />";
    data2 += "<input type='radio' name='data2' value='2' />Mukesh Ambani<br /><br />";
	data2 += "<input type='radio' name='data2' value='1' />Shiv Nadar<br /><br />";
	//htmlout += data2+ "<br />";
	
	var data3 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Which film actor inspires you?</b></td></tr></table>";
	data3 += "<input type='radio' name='data3' value='4' />Amitabh Bachhan<br />";
    data3 += "<input type='radio' name='data3' value='3' />Shahrukh Khan<br />";
    data3 += "<input type='radio' name='data3' value='2' />Amir Khan<br /><br />";
	data3 += "<input type='radio' name='data3' value='1' />Nana Patekar<br /><br />";
	//htmlout += data3+ "<br />";
	
	var data4 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Which word best describes you?</b></td></tr></table>";
	data4 += "<input type='radio' name='data4' value='4' />Humble<br />";
    data4 += "<input type='radio' name='data4' value='3' />Outgoing<br />";
    data4 += "<input type='radio' name='data4' value='2' />Stable headed<br /><br />";
	 data4 += "<input type='radio' name='data4' value='1' />Intense<br /><br />";
	//htmlout += data4+ "<br />";

	var data5 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>For your career, what would you like to be doing?</b></td></tr></table>";
	data5 += "<input type='radio' name='data5' value='4' />Professional - Lawyer, CA, Doctor<br />";
    data5 += "<input type='radio' name='data5' value='3' />Marketing, Sales, Advertising<br />";
    data5 += "<input type='radio' name='data5' value='2' />General Management<br /><br />";
	data5 += "<input type='radio' name='data5' value='1' />Entrepreneur, Self employed<br /><br />";
	//htmlout += data5+ "<br />";

	var data6 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Which Institution in Gurgaon had the most percentage of foreign summer internships?</b></td></tr></table>";
	data6 += "<input type='radio' name='data6' value='0' />Pearl School of Business<br />";
    data6 += "<input type='radio' name='data6' value='0' />PSB<br />";
    data6 += "<input type='radio' name='data6' value='0' />Pearl<br /><br />";
	 data6 += "<input type='radio' name='data6' value='0' />www.psbg.in<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data7 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Which Institution in Gurgaon is well known for its focus on entrepreneurship in its MBA and BBA programmes?</b></td></tr></table>";
	data7 += "<input type='radio' name='data7' value='0' />Pearl School of Business<br />";
    data7 += "<input type='radio' name='data7' value='5' />PSB<br />";
    data7 += "<input type='radio' name='data7' value='10' />Pearl<br /><br />";
	  data7 += "<input type='radio' name='data7' value='10' />www.psbg.in<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data8 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Where can you get a premier BBA and MBA degree with a unique focus on entrepreneurship, finance, marketing and HR?</b></td></tr></table>";
	data8 += "<input type='radio' name='data8' value='0' />Pearl School of Business<br />";
    data8 += "<input type='radio' name='data8' value='5' />PSB<br />";
    data8 += "<input type='radio' name='data8' value='10' />Pearl<br /><br />";
	data8 += "<input type='radio' name='data8' value='10' />www.psbg.in<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data9 = "<td valign='top' align='left' style='font-size:11px; padding-top:2px'>&nbsp;<b>Which institution has unique partnerhships with Sri Ram College of Commerce, Nottingham Trent University and Babcock University for BBA and MBA?</b></td></tr></table>";
	data9 += "<input type='radio' name='data9' value='0' />Pearl School of Business<br />";
    data9 += "<input type='radio' name='data9' value='5' />PSB<br />";
    data9 += "<input type='radio' name='data9' value='15' />Pearl<br /><br />";
	data9 += "<input type='radio' name='data9' value='15' />www.psbg.in<br /><br />";
	//htmlout += data6+ "<br />";
	
		
		
	for (var i = 0; i < 10 ; i++) 
	  { 
	  	var j = i+1;
	  	if(i > 4)
		{
	  		if(myNumArray[i] == 1)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data1+ "</td></tr>";	
			else if(myNumArray[i] == 2)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data2+ "</td></tr>";
			else if(myNumArray[i] == 3)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data3+ "</td></tr>";	
			else if(myNumArray[i] == 4)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data4+ "</td></tr>";
			else if(myNumArray[i] == 5)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data5+ "</td></tr>";	
			else if(myNumArray[i] == 6)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data6+ "</td></tr>";	
			else if(myNumArray[i] == 7)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data7+ "</td></tr>";	
			else if(myNumArray[i] == 8)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data8+ "</td></tr>";
			else if(myNumArray[i] == 9)
				table2html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data9+ "</td></tr>";	
			
		}
		else
		{
			if(myNumArray[i] == 1)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data1+ "</td></tr>";	
			else if(myNumArray[i] == 2)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data2+ "</td></tr>";
			else if(myNumArray[i] == 3)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data3+ "</td></tr>";	
			else if(myNumArray[i] == 4)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data4+ "</td></tr>";
			else if(myNumArray[i] == 5)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data5+ "</td></tr>";	
			else if(myNumArray[i] == 6)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data6+ "</td></tr>";	
			else if(myNumArray[i] == 7)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data7+ "</td></tr>";	
			else if(myNumArray[i] == 8)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data8+ "</td></tr>";
			else if(myNumArray[i] == 9)
				table1html += "<tr><td style='font-size:11px;'><table width='100%' bgcolor='#EAF1FB' cellpadding='0' cellspacing='0' height='35px'><tr><td width='34px' align='center' background='http://www.lkstechnology.com/Num_bg.png' style='background-repeat:no-repeat'><font color='#FFFFFF'>"+j+"</font></td>"+data9+ "</td></tr>";	
			
		}	  				
	  }	
	  table1html += "</table>";
	  table2html += "</table>";
	  htmlout += "<tr><td style='width:50%;'>"+table1html+"</td><td>"+table2html+"</td></tr></table>";
      div.innerHTML = htmlout;
   }

function init() 
{		
  loadFriends(); 
 populateMyAppData();
}